package com.example.testapp.activity.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.example.testapp.activity.http.RetryNetwork;

/**
 * 网络状态监听中心
 * Created by l on 2016/9/19.
 */
public class NetWorkCenter {

    private static RetryNetwork mRetry;

    public void setRetryNetwork(RetryNetwork r) {
         mRetry = r;
    }

    public void removeRetry() {
        mRetry = null;
    }

    /**
     * 判断是否有网络链接
     * @param context
     * @return
     */
    public static boolean isNetworkConnected(Context context) {
       if (context != null){
           ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
           NetworkInfo  mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
           if (mNetworkInfo != null){
               return mNetworkInfo.isAvailable();
           }
       }
        return false;
    }
}
